package com.example.badmintonWeb.config;
import com.example.badmintonWeb.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).excludePathPatterns(
                //此处添加不进行token验证的白名单
                "/user/register",
                "/user/login",
                "/admin/login",
                "/user/bookPlace",
                "/user/UnBookPlace",
                "/user/findGymMes",
                "/user/ShowAllOderByTel",
                "/user/FindAllGyms",
                "/admin/addGym",
                "/admin/notices",
                "/admin/addNotice",
                "/admin/GetUsersList",
                "/admin/DeleteGymById",
                "/user/editmessage",
                "/user/editpsw",
                "/admin/deleteNotice"

                       );
    }

    //允许3030端口跨域请求
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8081")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
    }

}